package com.thon.entity.system;

// Generated 2011-11-24 10:21:16 by Hibernate Tools 3.4.0.CR1

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.thon.entity.util.IdEntity;

/**
 * Attachment generated by hbm2java
 */
@Entity
@Table(name = "attachments")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Attachment extends IdEntity {

	private static final long serialVersionUID = -7761227854582585540L;
	private String contentType;
	private String fileName;
	private String fileUrl;
	private Integer fileSize;
	private Boolean existed;
	private Integer userId;
	private Date createdDate;
	private Boolean enabled;
	
	// helper
	private byte[] bytes;
	private String dimension;
	private int width;
	private int height;

	public Attachment() {
		enabled = true;
	}
	
	@Column(nullable=false)
	public String getContentType() {
		return this.contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	
	@Transient
	public String getName() {
		return StringUtils.substringBefore(fileName, ".");
	}

	public String getFileName() {
		return this.fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileUrl() {
		return this.fileUrl;
	}

	public void setFileUrl(String fileUrl) {
		this.fileUrl = fileUrl;
	}

	public Integer getFileSize() {
		return this.fileSize;
	}

	public void setFileSize(Integer fileSize) {
		this.fileSize = fileSize;
	}

	public Boolean getExisted() {
		return this.existed;
	}

	public void setExisted(Boolean existed) {
		this.existed = existed;
	}

	public Integer getUserId() {
		return this.userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Boolean getEnabled() {
		return this.enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	
	@Transient
	public String getSuffix() {
		return "."+StringUtils.substringAfterLast(fileName, ".");
	}

	@Transient
	public byte[] getBytes() {
		return bytes;
	}

	public void setBytes(byte[] bytes) {
		this.bytes = bytes;
	}

	@Transient
	public String getDimension() {
		return dimension;
	}

	public void setDimension(String dimension) {
		this.dimension = dimension;
	}
	
	@Transient
	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	@Transient
	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	

}
